package com.luocc.ccdemo.entity

import android.os.Parcel
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "video")
data class Video(
    @PrimaryKey
    val id: Int,
    @ColumnInfo
    val title: String?,
    @ColumnInfo(name = "cover_url")
    val coverUrl: String?,
    @ColumnInfo(name = "video_url")
    val videoUrl: String?,
    @ColumnInfo
    val duration: String?,
    @ColumnInfo
    val username: String?,
    @ColumnInfo(name = "user_picture")
    val userPic: String?,
    @ColumnInfo(name = "insert_time")
    var insertTime: String?,
    @ColumnInfo
    var collect: Boolean?,
    @ColumnInfo
    var seen: Boolean?
) : Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readInt(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readValue(Boolean::class.java.classLoader) as? Boolean,
        parcel.readValue(Boolean::class.java.classLoader) as? Boolean
    )

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(id)
        parcel.writeString(title)
        parcel.writeString(coverUrl)
        parcel.writeString(videoUrl)
        parcel.writeString(duration)
        parcel.writeString(username)
        parcel.writeString(userPic)
        parcel.writeString(insertTime)
        parcel.writeValue(collect)
        parcel.writeValue(seen)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<Video> {
        override fun createFromParcel(parcel: Parcel): Video {
            return Video(parcel)
        }

        override fun newArray(size: Int): Array<Video?> {
            return arrayOfNulls(size)
        }
    }
}
